<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- AdThrive Head Tag Manual -->
    <script data-no-optimize="1" data-cfasync="false">
      (function (w, d) {
        w.adthrive = w.adthrive || {};
        w.adthrive.cmd = w.adthrive.cmd || [];
        w.adthrive.plugin = "adthrive-ads-manual";
        w.adthrive.host = "ads.adthrive.com";
        var s = d.createElement("script");
        s.async = true;
        s.referrerpolicy = "no-referrer-when-downgrade";
        s.src =
          "https://" +
          w.adthrive.host +
          "/sites/643436a4e6d20859e40a446b/ads.min.js?referrer=" +
          w.encodeURIComponent(w.location.href) +
          "&cb=" +
          (Math.floor(Math.random() * 100) + 1);
        var n = d.getElementsByTagName("script")[0];
        n.parentNode.insertBefore(s, n);
      })(window, document);
    </script>
    <!-- End of AdThrive Head Tag -->

    <!-- Global site tag (gtag.js) - Google Analytics -->

    <script
      async
      src="https://www.googletagmanager.com/gtag/js?id=UA-79254642-6"
    ></script>

    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag("js", new Date());

      gtag("config", "UA-79254642-6");
    </script>

    <meta charset="utf-8" />
    <title>Bubble map &#124; the D3 Graph Gallery</title>

    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />
    <meta
      name="description"
      content="How to build a map with markers on top with Javascript and D3.js: from the most basic example to highly customized examples."
    />
    <meta
      name="keywords"
      content="Data,Dataviz,Datavisualization,Javascript,D3,D3.js,area chart"
    />
    <meta name="author" content="Yan Holtz" />
    <link rel="icon" href="img/logo/D3_single_small.png" />

    <meta
      property="og:title"
      content="Bubble map &#124; the D3 Graph Gallery"
    />
    <meta property="og:image" content="img/overview_RGG.png" />
    <meta
      property="og:description"
      content="How to build a map with markers on top with Javascript and D3.js: from the most basic example to highly customized examples."
    />

    <!-- Bootstrap core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />

    <!-- Custom fonts for this template -->
    <link
      href="vendor/font-awesome/css/font-awesome.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://fonts.googleapis.com/css?family=Montserrat:400,700"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://fonts.googleapis.com/css?family=Kaushan+Script"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700"
      rel="stylesheet"
      type="text/css"
    />

    <!-- Custom styles for this template -->
    <link href="css/agency.css" rel="stylesheet" />

    <!-- JQUERY -->
    <script src="vendor/jquery/jquery.min.js"></script>

    <!-- D3.JS v4 -->
    <script src="js/d3.v4.js"></script>
    <script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
    <script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>

    <!-- JQUERY -->
  </head>

  <body id="page-top">
    <!-- THIS ALLOWS TO INSERT THE MENU THAT IS STORED IN A MENU.HTML FILE-->
    <nav class="navbar navbar-expand-lg fixed-top" id="mainNav"></nav>
    <script>
      $(function () {
        $("#mainNav").load("html_chunk/menu.html");
      });
    </script>

    <!-- THIS ALLOWS TO INSERT THE MODAL OF THE MENU THAT IS STORED IN A MENU_MODAL.HTML FILE-->
    <div id="modal_menu_insertion"></div>
    <script>
      $(function () {
        $("#modal_menu_insertion").load("html_chunk/menu_modal.html");
      });
    </script>

    <!-- Header -->
    <header class="masthead" style="padding-top: 150px; padding-bottom: 80px">
      <div class="textlanding">
        <h1>Bubble map</h1>
        <hr class="short_hr" />
        <br />
        <ul class="list-inline social-buttons">
          <li class="list-inline-item">
            <a href="https://twitter.com/R_Graph_Gallery">
              <i class="fa fa-twitter"></i>
            </a>
          </li>
          <li class="list-inline-item social-buttons">
            <a href="https://github.com/holtzy">
              <i class="fa fa-github" style="color: white"></i>
            </a>
          </li>
          <li class="list-inline-item social-buttons">
            <a href="https://www.linkedin.com/in/yan-holtz-2477534a/">
              <i class="fa fa-linkedin"></i>
            </a>
          </li>
          <li class="list-inline-item social-buttons">
            <a href="https://www.yan-holtz.com">
              <i class="fa fa-home"></i>
            </a>
          </li>
        </ul>
        <br /><br />
        <p style="max-width: 700px; margin: auto">
          This section is dedicated to map with <u>markers</u> displayed on top
          of it. These markers can be circles with size proportional to a
          numerical value: that makes a
          <a href="https://www.data-to-viz.com/graph/bubblemap.html"
            >bubble map</a
          >. Before exploring this section, learn how to build the
          <a href="backgroundmap.html">map background</a> with javascript.
        </p>
      </div>
    </header>

    <!-- THIS ALLOWS TO INSERT THE ADVERTISEMENT BANNER THAT IS STORED IN A BANNER.HTML FILE-->
    <div id="position_for_images"></div>
    <script>
      $(function () {
        $("#position_for_images").load("html_chunk/images.html");
      });
    </script>

    <!-- ======================== PORTFOLIO SECTION ============================ --><!-- Images must be 480 x 480, resize them with ./script_reformat_img.sh output_name.png -->
    <section class="bg" id="portfolio" style="padding-top: 10px">
      <div class="container">
        <div class="mySeryTitle">From a <code>geoJson</code> file</div>
        <hr />
        <p>
          Input data for maps is <code>geoJson</code> format. D3.js works very
          well to display this kind of information using <code>path</code>.
        </p>
        <div id="portfolio-items" class="row">
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="graph/bubblemap_basic.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Most basic</p>
                  <hr />
                  <p class="explanation_portfolio">
                    The most basic bubble map you can do in d3.js. Keeping only
                    the core code.<br /><br />Input data format: geoJson +
                    javascript object
                  </p>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/graph/bubblemap_basic.png"
                alt=""
              />
            </a>
          </div>
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="graph/bubblemap_tooltip.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Add tooltip</p>
                  <hr />
                  <p class="explanation_portfolio">
                    Pretty useful to add a tooltip to add more information
                    concerning the marker.
                  </p>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/graph/bubblemap_tooltip.gif"
                alt=""
              />
            </a>
          </div>
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a
              class="portfolio-link"
              href="graph/bubblemap_circleFeatures.html"
            >
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Circle features</p>
                  <hr />
                  <p class="explanation_portfolio">
                    How to map circle size and color to data?
                  </p>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/graph/bubblemap_circleFeatures.png"
                alt=""
              />
            </a>
          </div>
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="graph/bubble_legend.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Legend</p>
                  <hr />
                  <p class="explanation_portfolio">
                    How to build a nice legend to illustrate bubble size.
                  </p>
                </div>
              </div>
              <img class="img-fluid" src="img/graph/bubble_legend.png" alt="" />
            </a>
          </div>
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="graph/bubblemap_buttonControl.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Group selection</p>
                  <hr />
                  <p class="explanation_portfolio">
                    Add a button to select displayed group, with smooth
                    transition.
                  </p>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/graph/bubblemap_buttonControl.gif"
                alt=""
              />
            </a>
          </div>
        </div>

        <br /><br /><br /><br />
        <div class="mySeryTitle">Template</div>
        <hr />
        <p>
          A clean template based on my
          <a href="https://www.data-to-viz.com/story/GPSCoordWithoutValue.html"
            >#surf project</a
          >. I harvested tweet containing the <u>#surf</u> hashtag for ~ 1 year
          and geocoded people home location. Here is where the surfers live! You
          can read more about this project
          <a href="https://www.data-to-viz.com/story/GPSCoordWithoutValue.html"
            >here</a
          >.
        </p>
        <a
          class="btn btn-secondary btn-md text-uppercase"
          href="graph/bubblemap_template.html"
          >See code</a
        >
        <center><svg id="my_dataviz" width="1200" height="490"></svg></center>

        <br /><br /><br /><br /><br /><br />
        <div class="mySeryTitle">
          Using the <code>Leaflet.js</code> open source library
        </div>
        <hr />
        <p>
          <a href="https://leafletjs.com/examples.html">Leaflet</a> is an
          open-source JavaScript library for mobile-friendly interactive maps.
          Awesome for background maps. See the range of background tiles you can
          use
          <a href="https://leaflet-extras.github.io/leaflet-providers/preview/"
            >here</a
          >
          and <a href="https://wiki.openstreetmap.org/wiki/Tiles">here</a>.
        </p>
        <div id="portfolio-items" class="row">
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="graph/bubblemap_leaflet_basic.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Basic bubblemap with leaflet</p>
                  <hr />
                  <p class="explanation_portfolio">
                    A very basic example showing how to add circles with d3 on
                    top of the leaflet.js background.
                  </p>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/graph/bubblemap_leaflet_basic.png"
                alt=""
              />
            </a>
          </div>
        </div>

        <br /><br /><br /><br />
        <div class="mySeryTitle">Selection of blocks</div>
        <hr />
        <p>
          A few blocks with more complicated codes to showcase the possibility
          of the <code>d3-sankey </code>plugin
        </p>
        <div id="portfolio-items" class="row">
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a
              class="portfolio-link"
              href="https://bost.ocks.org/mike/bubble-map/"
            >
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Mike's tutorial on bubble map</p>
                  <hr />
                  <p class="explanation_portfolio">
                    A complete tutorial on bubble map by Mike Bostock, d3.js
                    creator.
                  </p>
                </div>
              </div>
              <img
                class="img-fluid showBlock"
                src="img/block/block_bubblemapMike.png"
                alt="All d3 map projection"
              />
            </a>
          </div>
          <div class="col-md-4 col-sm-6 portfolio-item">
            <a class="portfolio-link" href="https://leafletjs.com">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <p>Leaflet documentation</p>
                  <hr />
                  <p class="explanation_portfolio">
                    Link to the leaflet website: awesome doc for awesome maps.
                  </p>
                </div>
              </div>
              <img
                class="img-fluid showBlock"
                src="img/block/block_backgroundmapLeaflet.png"
                alt="circular barchart"
              />
            </a>
          </div>
        </div>
      </div>
    </section>

    <!-- ======================================================================= -->

    <!-- ============================ Script template bubble map ============================ -->

    <script>
      // The svg
      var svg = d3.select("svg"),
        width = +svg.attr("width"),
        height = +svg.attr("height");

      // Map and projection
      var projection = d3
        .geoMercator()
        .center([0, 20]) // GPS of location to zoom on
        .scale(160) // This is like the zoom
        .translate([width / 2, height / 2]);

      d3.queue()
        .defer(
          d3.json,
          "https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world.geojson"
        ) // World shape
        .defer(
          d3.csv,
          "https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/data_gpsLocSurfer.csv"
        ) // Position of circles
        .await(ready);

      function ready(error, dataGeo, data) {
        // Create a color scale
        var allContinent = d3
          .map(data, function (d) {
            return d.homecontinent;
          })
          .keys();
        var color = d3
          .scaleOrdinal()
          .domain(allContinent)
          .range(d3.schemePaired);

        // Add a scale for bubble size
        var valueExtent = d3.extent(data, function (d) {
          return +d.n;
        });
        var size = d3
          .scaleSqrt()
          .domain(valueExtent) // What's in the data
          .range([1, 80]); // Size in pixel

        // Draw the map
        svg
          .append("g")
          .selectAll("path")
          .data(dataGeo.features)
          .enter()
          .append("path")
          .attr("fill", "#b8b8b8")
          .attr("d", d3.geoPath().projection(projection))
          .style("stroke", "none")
          .style("opacity", 0.3);

        // Add circles:
        svg
          .selectAll("myCircles")
          .data(
            data
              .sort(function (a, b) {
                return +b.n - +a.n;
              })
              .filter(function (d, i) {
                return i < 1000;
              })
          )
          .enter()
          .append("circle")
          .attr("cx", function (d) {
            return projection([+d.homelon, +d.homelat])[0];
          })
          .attr("cy", function (d) {
            return projection([+d.homelon, +d.homelat])[1];
          })
          .attr("r", function (d) {
            return size(+d.n);
          })
          .style("fill", function (d) {
            return color(d.homecontinent);
          })
          .attr("stroke", function (d) {
            if (d.n > 2000) {
              return "white";
            } else {
              return "none";
            }
          })
          .attr("stroke-width", 1)
          .attr("fill-opacity", 0.4);

        // Add title and explanation
        svg
          .append("text")
          .attr("text-anchor", "end")
          .style("fill", "black")
          .attr("x", width - 130)
          .attr("y", 30)
          .attr("width", 90)
          .html("WHERE SURFERS LIVE")
          .style("font-size", 18);
        // Add title and explanation
        svg
          .append("text")
          .attr("text-anchor", "end")
          .style("fill", "black")
          .attr("x", width - 130)
          .attr("y", 55)
          .attr("width", 90)
          .html("Number of #surf tweet harvested in a year")
          .style("font-size", 13);

        // --------------- //
        // ADD LEGEND //
        // --------------- //

        // Add legend: circles
        var valuesToShow = [100, 5000, 20000];
        var xCircle = 120;
        var xLabel = 200;
        svg
          .selectAll("legend")
          .data(valuesToShow)
          .enter()
          .append("circle")
          .attr("cx", xCircle)
          .attr("cy", function (d) {
            return height - size(d);
          })
          .attr("r", function (d) {
            return size(d);
          })
          .style("fill", "none")
          .attr("stroke", "black");

        // Add legend: segments
        svg
          .selectAll("legend")
          .data(valuesToShow)
          .enter()
          .append("line")
          .attr("x1", function (d) {
            return xCircle + size(d);
          })
          .attr("x2", xLabel)
          .attr("y1", function (d) {
            return height - size(d);
          })
          .attr("y2", function (d) {
            return height - size(d);
          })
          .attr("stroke", "black")
          .style("stroke-dasharray", "2,2");

        // Add legend: labels
        svg
          .selectAll("legend")
          .data(valuesToShow)
          .enter()
          .append("text")
          .attr("x", xLabel + 3)
          .attr("y", function (d) {
            return height - size(d);
          })
          .text(function (d) {
            return d;
          })
          .style("font-size", 11)
          .attr("alignment-baseline", "middle");
      }
    </script>

    <!-- ============================ RELATED SECTION ============================ -->
    <section
      class="bg-light"
      id="portfolio_landing"
      style="padding-top: 30px; padding-bottom: 30px"
    >
      <div class="container">
        <p class="mySeryTitle">Related chart types</p>
        <hr />
        <div class="row">
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="backgroundmap.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img class="img-fluid" src="img/section/Map150.png" alt="" />
            </a>
            <div class="captionPortfolio">Map</div>
          </div>
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="choropleth.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/section/Choropleth150.png"
                alt=""
              />
            </a>
            <div class="captionPortfolio">Choropleth</div>
          </div>
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="hexbinmap.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/section/MapHexbin150.png"
                alt=""
              />
            </a>
            <div class="captionPortfolio">Hexbin map</div>
          </div>
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="cartogram.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/section/Cartogram150.png"
                alt=""
              />
            </a>
            <div class="captionPortfolio">Cartogram</div>
          </div>
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="connectionmap.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/section/ConnectedMap150.png"
                alt=""
              />
            </a>
            <div class="captionPortfolio">Connection</div>
          </div>
          <div class="col-md-2 col-sm-4 portfolio-item">
            <a class="portfolio-link" href="bubblemap.html">
              <div class="portfolio-hover">
                <div class="portfolio-hover-content">
                  <i class="fa fa-plus fa-3x"></i>
                </div>
              </div>
              <img
                class="img-fluid"
                src="img/section/BubbleMap150.png"
                alt=""
              />
            </a>
            <div class="captionPortfolio">Bubble map</div>
          </div>
        </div>
      </div>
    </section>

    <!-- ============================ CONTACT SECTION ============================ -->

    <!-- ANCHOR -->
    <a name="contactanchor"></a>

    <section id="contact" class="bg" style="background-color: white"></section>

    <!-- THIS ALLOWS TO INSERT THE CONTACT CHUNK THAT IS STORED IN A CONTACT.HTML FILE-->
    <script>
      $(function () {
        $("#contact").load("html_chunk/contact.html");
      });
    </script>

    <!-- ============================ FOOTER SECTION ============================ -->
    <footer class="bg-light" id="myFooter"></footer>

    <!-- Start Added by AdThrive -->
    <script
      type="text/javascript"
      async
      src="https://btloader.com/tag?o=5698917485248512&upapi=true&domain=d3-graph-gallery.com"
    ></script>
    <script>
      !(function () {
        "use strict";
        var e;
        (e = document),
          (function () {
            var t, n;
            function r() {
              var t = e.createElement("script");
              (t.src =
                "https://cafemedia-com.videoplayerhub.com/galleryplayer.js"),
                e.head.appendChild(t);
            }
            function a() {
              var t = e.cookie.match("(^|[^;]+)\s*__adblocker\s*=\s*([^;]+)");
              return t && t.pop();
            }
            function c() {
              clearInterval(n);
            }
            return {
              init: function () {
                var e;
                "true" === (t = a())
                  ? r()
                  : ((e = 0),
                    (n = setInterval(function () {
                      (100 !== e && "false" !== t) || c(),
                        "true" === t && (r(), c()),
                        (t = a()),
                        e++;
                    }, 50)));
              },
            };
          })().init();
      })();
    </script>
    <!-- End Added by AdThrive -->

    <!-- THIS ALLOWS TO INSERT THE FOOTER THAT IS STORED IN A FOOTER.HTML FILE-->
    <script>
      $(function () {
        $("#myFooter").load("html_chunk/footer.html");
      });
    </script>

    <!-- ============================ -->

    <!-- =============== JAVASCRIPT SECTION =============== -->

    <!-- Bootstrap core JavaScript -->
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Plugin JavaScript -->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Contact form JavaScript -->
    <script src="js/jqBootstrapValidation.js"></script>
    <script src="js/contact_me.js"></script>

    <!-- Custom scripts for this template -->
    <script src="js/agency.min.js"></script>

    <!-- Activate the bootstrap tooltip, must be after jQuery load -->
    <script>
      $(function () {
        $('[data-toggle="tooltip"]').tooltip();
      });
    </script>

    <!--============================== -->
  </body>
</html>
